Next | Prev | Up | Top | Contents | Index

Fundamental Types for C

This section discusses 'fundamental types' useful in converting C code from 32-bit to 32- or 64-bit. These take the form of typedefs, and are available in the file <sgidefs.h>. These typedefs are enabled by compiler predefines, which are also described. This discussion is entirely from the C point of view, although the predefines discussed are also emitted by the other compilers.

It is desirable to have source code that can be compiled either in 32-bit mode or 64-bit mode. An example is libc, which we provide in both 32-bit and 64-bit form. (In this discussion, 32-bit code means mips1 or mips2, 64-bit code means mips3 or mips4.)

As previously mentioned, the compilation model chosen for 64-bit objects is referred to as LP64, where longs and pointers are 64 bits, and ints remain at 32 bits. Since ints and pointers are no longer the same size, and ints and longs are not the same size, a lot of code can break in this compilation model.

The typedefs discussed, in their naming convention, explicitly call out certain attributes of the typedef. The goal of this, by naming those attributes, is to ease the long term maintenance of code which has to compile in both the 32-bit and 64-bit models.

The typedefs are enabled by predefines from the compilers. The predefines that the compilers emit are:

For MIPS1executables:

-D_MIPS_FPSET=16
-D_MIPS_ISA=_MIPS_ISA_MIPS1
-D_MIPS_SIM=_MIPS_SIM_ABI32
-D_MIPS_SZINT=32
-D_MIPS_SZLONG=32
-D_MIPS_SZPTR=32
For MIPS3 executables:

-D_MIPS_FPSET=32
-D_MIPS_ISA=_MIPS_ISA_MIPS3
-D_MIPS_SIM=_MIPS_SIM_ABI64
-D_MIPS_SZINT=32
-D_MIPS_SZLONG=64
-D_MIPS_SZPTR=64
For MIPS4 executables:

-D_MIPS_FPSET=32
-D_MIPS_ISA=_MIPS_ISA_MIPS4
-D_MIPS_SIM=_MIPS_SIM_ABI64
-D_MIPS_SZINT=32
-D_MIPS_SZLONG=64
-D_MIPS_SZPTR=64
The explanation of these predefines is as follows:

An example of the use of these predefined variables:

#if (_MIPS_SZLONG == 32)

typedef int ssize_t;

#endif
#if (_MIPS_SZLONG == 64)

typedef long ssize_t;

#endif 
The typedefs following are largely self-explanatory. These are from <sgidefs.h>:

__int32_t     Signed 32 bit integral type
__uint32_t    Unsigned 32 bit integral type
__int64_t     Signed 64 bit integral type
__uint64_t    Unsigned 64 bit integral type
These are "pointer-sized int" and "pointer-sized unsigned int' respectively. As such, they are guaranteed to have the same number of bits as a pointer.

__psint_t
__psunsigned_t
These are 'scaling int' and 'scaling unsigned' respectively, and are intended for variables that you want to grow as the code is compiled in the 64-bit model.

__scint_t
__scunsigned_t
The usefulness of these types is that they free the coder from having to know the underlying compilation model -- indeed, that model can change, and the code should still work. In this respect, use of these typedefs is better than replacing the assumption, that an int and a pointer are the same size with the new assumption, that a long and a pointer are the same size.'



Next | Prev | Up | Top | Contents | Index